﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jermaine.Extensions
{
    public class Patterns
    {
        /// <summary>
        /// 日期
        /// </summary>
        public static readonly Pattern DateTime = new Pattern("DateTime", 0, @"^(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29))$)|(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))$");

        /// <summary>
        /// 固定电话
        /// </summary>
        public static readonly Pattern Phone = new Pattern("Phone", 1, @"^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$");
        
        /// <summary>
        /// 移动电话 
        /// </summary>
        public static readonly Pattern Mobile = new Pattern("Mobile", 2, @"^1(?:3[0-9]|5[0-9]|8[0-9]|4[0-9])\d{8}$");

        /// <summary>
        /// 邮箱
        /// </summary>
        public static readonly Pattern Email = new Pattern("Email",3,@"^\w+((-\w+)(\.\w+))*\@[A-Za-z0-9]+((\.-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$");

        /// <summary>
        /// 数字
        /// </summary>
        public static readonly Pattern Number = new Pattern("Number", 4, @"^[+-]?\d+(\.\d+)?$");

        /// <summary>
        /// IP地址
        /// </summary>
        public static readonly Pattern IP = new Pattern("IP", 5, @"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])");

        /// <summary>
        /// 汉字
        /// </summary>
        public static readonly Pattern ChineseCharacter = new Pattern("ChineseCharacter", 6, @"^[\u4e00-\u9fa5]$");

        public class Pattern
        {
            public Pattern(string name, int value, string regex) {
                this.Name = name;
                this.Value = value;
                this.Regex = regex;
            }

            public String Name { get; private set; }
            public int Value { get; private set; }
            public String Regex { get; set; }
        }
    }
}
